/**
 * @param {number[]} nums
 * @return {number}
 */
 var majorityElement = function(nums) {
    let num=nums[0],count=0;
    for(let i=0;i<nums.length;i++){
        if(nums[i]==num){
            count++;
        }
        else{
            if(count==0){
                num=nums[i]
                count=1;
            }
            else{
                count--;
            }
        }
    }
    return num;
};